<?php

use app\api\controller\v1\Clue as ClueModel;

if (!defined("APP_PATH")) {
    define('APP_PATH', __DIR__ . '/../application/');
    // 加载框架引导文件
    require __DIR__ . '/../thinkphp/start.php';
}


// 7/9/10点运行
// 重复推送 未推送线索
function repeat_push_clue()
{
    echo '开始执行的时间：' . date('Y-m-d H:i:s') . "\r\n";

    $hour = intval(date("H"));
    if (!in_array($hour, [7, 8, 9, 10])) {
        echo '非7/9/10点不重新推送'. "\r\n";
        exit;
    }

    $yesterday = strtotime(date('Y-m-d', strtotime('-2 days')));
    $clueArr = \db('clue')->where('create_time', '>=', $yesterday)->where('status', 0)->select();
    $clue_model = new ClueModel();
    foreach ($clueArr as $v) {
        echo  $v['id']."\r\n";
        $push_res = $clue_model->cluePush($v, false);
        if ($push_res['code'] == 200) { // 推送成功 延迟
            sleep(mt_rand(120, 300));
        }
    }

    echo '结束执行的时间：' . date('Y-m-d H:i:s') . "\r\n";
}

repeat_push_clue();

